﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;

public partial class Product : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
       //product.DataSource=myProducts;
       //product.DataBind();
        //if (!this.IsPostBack)
            //RegisterStartupScript();


    }

    private DataSet GetPicture()
        {
            DataSet myProducts=new DataSet();
            myProducts.ReadXml(MapPath("products.xml"));       
            return myProducts;
        }
        private void RegisterStartupScript()
        {
            string strKey = "picflash";

            StringBuilder str = new StringBuilder();
            str.Append("<script type=text/javascript>function indexpic(){var focus_width=287;var focus_height=173;var text_height=20;");

            str.Append("var swf_height = focus_height+text_height;");

            string pics = "";//路径
            string links = "";//连接
            string texts = "";//标题

            //从数据库中动态获取数据，将数据写入ds中
            DataSet ds = this.GetPicture();


            int count = ds.Tables[0].Rows.Count;
            for (int i = 0; i < count; i++)
            {

                //将数据库中的数据写入flash的参数
                if (i != 0) pics += "|" + ds.Tables[0].Rows[i]["index_pic"].ToString();
                else pics += ds.Tables[0].Rows[i]["index_pic"].ToString();
                if (i != 0) links += "|" + "SingleInfo.aspx?id=" + ds.Tables[0].Rows[i]["id"].ToString();
                else links += "SingleInfo.aspx?id=" + ds.Tables[0].Rows[i]["id"].ToString();
                if (i != 0) texts += "|" + ds.Tables[0].Rows[i]["title"].ToString();
                else texts += ds.Tables[0].Rows[i]["title"].ToString();

            }
            str.Append("var pics='" + pics + "';");
            str.Append(" var links='" + links + "';");
            str.Append(" var texts='" + texts + "';");            

            //str.Append("document.write('<object classid=/""clsid:d27cdb6e-ae6d-11cf-96b8-444553540000/"" codebase=/""http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0/"" width=/""'+ focus_width +'/"" height=/""'+ swf_height +'/"">');");
            //str.Append("document.write('<param name=/""allowScriptAccess/"" value=/""sameDomain/""><param name=/""movie/"" value=/""images/pixviewer.swf/""><param name=/""quality/"" value=/""high/""><param name=/""bgcolor/"" value=/""#999898/"">');");
            //str.Append("document.write('<param name=/""menu/"" value=/""false/""><param name=wmode value=/""opaque/"">');");
            //str.Append("document.write('<param name=/""FlashVars/"" value=/""pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'/"">');");
            //str.Append("document.write('</object>');}</script>");
            Page.RegisterClientScriptBlock(strKey, str.ToString());//注册indexpic函数
        }

}